﻿namespace CommonUtils
{
    public static class Language
    {
        private static Map<LanguageType, LanguageProvider> providers = new Map<LanguageType, LanguageProvider>();

        public static string Get(string key, LanguageType languageType = default)
        {
            if (!providers.ContainsKey(languageType))
                providers[languageType] = new LanguageProvider(languageType);
            return providers[languageType].Get(key);
        }

        public static string Translate(string value)
        {
            var api = "http://fanyi.youdao.com/translate?&doctype=json&type=AUTO&i=" + value.UrlDecode();
            var result = HttpUtil.Get(api);
            if (result.IsSuccessStatusCode)
                return result.ReadJObject()["translateResult"][0][0]["tgt"].ToObject<string>();
            return value;
        }
    }
}
